Skip to content

feat(tools): ast-grep structural search/rewrite and gh CLI operations - #19

Merged
Steel-tech merged 2 commits into
mainfrom
claude/best-in-class-github-commit-ksgga0
Aug 19, 2026
Merged

feat(tools): ast-grep structural search/rewrite and gh CLI operations#19
Steel-tech merged 2 commits into
mainfrom
claude/best-in-class-github-commit-ksgga0

Conversation

@Steel-tech

@Steel-tech Steel-tech commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

The external-surface tranche from docs/TOOLS.md: three tools wrapping two proven binaries, each degrading explicitly — never silently — when its binary is absent.

ast_grep / ast_edit — structural code search and rewrite (ast-grep)

  • ast_grep matches a pattern against the syntax tree (metavariables like $A, $$$ARGS), rendered as file:line results on the workspace's 1-based convention, capped at 200 matches. Parallel- and replay-safe.
  • ast_edit rewrites those matches, previewing the diff by default and writing only on apply: true — the catalog's preview-then-resolve folded into one tool. Previews are parallel-safe; applies are serial and run through the sandbox's shell wrapper like bash (Seatbelt-confined on macOS).
  • Binary discovery at call time: ast-grep, then sg — accepted only when --version identifies ast-grep, since plain sg is the Unix shell-group utility. Absence is a clear error with an install hint.
  • Registry: both join Registry::standard(); inspect-mode pen children get read-only ast_grep.

github — gh CLI operations

  • Raw gh arguments as an array, no shell in between: nothing needs quoting, nothing can be injected.
  • The runtime derives parallel safety from the verb: views/lists/diffs/checks/searches ride alongside anything; mutations and the open-ended api stay serial, defaults closed.
  • A network-denying sandbox refuses the call outright; a missing binary errors with the install + gh auth login hint; prompts are disabled so headless runs can't wedge.
  • gh acts with the user's own login on remote state — outside what workspace write-confinement governs — so it registers on top-level runs only; pen children keep to the workspace.

Validation

  • Stub-binary tests cover flag construction, output rendering (ast-grep's 0-based lines → 1-based, multi-line elision), the preview/apply split, failure passthrough, and parallel-safety matrices — these run everywhere, including CI. Stub helpers carry an ETXTBSY warm-up so parallel test runs can't race a fresh script's exec.
  • A real-binary roundtrip (search → preview leaves the file untouched → apply rewrites it) ran green against ast-grep 0.45.1 locally; it skips cleanly where the binary is absent, like CI. One real-behavior discovery baked in: ast-grep reports "Applied N changes" on stderr, so the apply summary reads both streams.
  • Full gates: cargo fmt --all --check, cargo clippy --workspace --all-targets -- -D warnings, cargo test --workspace (repeated runs) — all green, 188 tests.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KoSjfcJPjXpkVLTS2Vxwwr

`ast_grep` matches a pattern against the syntax tree — metavariables and
all — and renders `file:line` results on the workspace's 1-based
convention. `ast_edit` rewrites those matches, previewing the diff by
default and writing only on `apply: true`, so the model reviews before
anything lands on disk; the catalog's preview-then-resolve, folded into
one tool.

The binary is discovered at call time (`ast-grep`, then `sg`, accepted
only if `--version` identifies ast-grep — plain `sg` is the shell-group
utility), and absence is a clear error with an install hint, never a
silent fallback to text search. Applies under a sandbox run through the
same shell wrapper as `bash`, Seatbelt-confined where the OS enforces
it. The apply summary is read from stderr, where ast-grep actually
reports it.

Stub-binary tests cover flag construction, rendering, and the
preview/apply split everywhere (with an ETXTBSY warm-up so parallel
test runs can't race a fresh script's exec); a real-binary roundtrip
runs when ast-grep is installed and skips where it isn't, like CI.
Inspect-mode pen children get `ast_grep`; work children get both.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KoSjfcJPjXpkVLTS2Vxwwr
@coderabbitai

coderabbitai Bot commented Aug 19, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Steel-tech, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 43 minutes

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits within each organization.

For paid Pro and Pro+ reviews, CodeRabbit uses a developer's included PR review attempts over the past 7 days to set the current hourly allowance. At typical activity levels, the full plan allowance applies. Higher sustained activity can lower the allowance until earlier attempts leave the 7-day window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 78f22924-4e08-4099-8565-b4c2ecc32b55

📥 Commits

Reviewing files that changed from the base of the PR and between 3ffd17c and 6059d89.

📒 Files selected for processing (7)
  • README.md
  • crates/cli/src/main.rs
  • crates/harness/src/pen.rs
  • crates/tools/src/ast.rs
  • crates/tools/src/github.rs
  • crates/tools/src/lib.rs
  • docs/TOOLS.md

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

One tool, raw `gh` arguments as an array — no shell in between, so
nothing needs quoting and nothing can be injected. The tool adds what
gh cannot know: the runtime derives parallel safety from the verb
(views, lists, diffs, checks, and searches ride alongside anything;
mutations and the open-ended `api` stay serial, defaults closed), a
network-denying sandbox refuses the call outright, and a missing
binary errors with the install + `gh auth login` hint. Prompts are
disabled so a headless run can never wedge on an interactive question.

gh acts with the user's own login on remote state, which the workspace
sandbox's write confinement deliberately does not govern — it fences
the filesystem, not GitHub. Accordingly the tool registers on
top-level runs only; pen children keep to the workspace.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KoSjfcJPjXpkVLTS2Vxwwr
@Steel-tech Steel-tech changed the title feat(ast): structural search and preview-first rewrite via ast-grep feat(tools): ast-grep structural search/rewrite and gh CLI operations Aug 19, 2026
@Steel-tech
Steel-tech merged commit 13c0508 into main Aug 19, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants